from asyncio.windows_events import NULL
import pygame
import random
import os
from settings import *

# basic color settings
white = (255, 255, 255)
black = (0, 0, 0)
gray = (128, 128, 128)
red = (200, 0, 0)
green = (0, 200, 0)
bright_red = (255, 0, 0)
bright_green = (0, 255, 0)
blue = (0, 0, 255)

my_set = Settings()  # 用的是设置类  系统外观设置
pygame.init()
pygame.mixer.init()
# 游戏窗口初始化
window = pygame.display.set_mode((my_set.screen_width, my_set.screen_height))  # 窗口大小
screen = pygame.display.get_surface()
# 设置logo和界面标题
game_icon = pygame.image.load('../graphics/changbao.png')
pygame.display.set_icon(game_icon)
pygame.display.set_caption(my_set.name)
# 加载背景和图标
background_image = pygame.image.load('../graphics/background.jpg').convert()
clock = pygame.time.Clock()  # 帧率显示,先定义一个时间对象

def text_objects(text, font):
    textSurface = font.render(text, True, black)
    return textSurface, textSurface.get_rect()


def button(imagename,x,y,w,h,action=None):
    mouse = pygame.mouse.get_pos()
    click = pygame.mouse.get_pressed()
    button_image = pygame.image.load(imagename)
    window.blit(button_image,(x, y, w, h))
    if x + w > mouse[0] > x and y + h > mouse[1] > y:
        if click[0]==1 and action!=None:
            pygame.quit()
            os.system(action)
            quit()
        elif click[0]==1 and action==None:
            pygame.quit()
            quit()
        
while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            quit()
    # window.fill(white)
    screen.blit(background_image,(0,0))
    button('../graphics/start.png',190,400,200,60,"cd ../../level_1/mainpy & python main.py")
    button('../graphics/quit.png',190,500,200,60, None)
    pygame.display.update()
    clock.tick(15)